﻿
<div id="IndexPageQuanHuyenAddUp">
    <div id="page_quan_huyen_TableContainer"></div>
</div>
<script type="text/javascript">

    $(document).ready(function () {



        $("#IndexPageQuanHuyenAddUp").css('width', $(window).width() - 10);
        $("#IndexPageQuanHuyenAddUp").height($(window).height() - 100);

        $("#IndexPageQuanHuyenAddUp").mask("Đang tải dữ liệu");

        $('#page_quan_huyen_TableContainer').jtable({

            title: 'DS QUẬN HUYỆN',
            openChildAsAccordion: true,
            actions: {
                listAction: _nameSubDomain + '/QuanHuyen/ListQuanHuyen',
                deleteAction: function (postData) {
                    console.log("deleting from custom function...");
                    return $.Deferred(function ($dfd) {

                        $("#IndexPageQuanHuyenAddUp").mask("Dữ liệu đang được xóa");

                        $.ajax({
                            url: _nameSubDomain + '/QuanHuyen/DeleteQuanHuyen',
                            type: 'POST',
                            dataType: 'json',
                            data: postData,
                            success: function (data) {

                                $dfd.resolve(data);
                                setTimeout(function () { $("#IndexPageQuanHuyenAddUp").unmask(); }, 600);

                            },
                            error: function () {
                                $dfd.reject();
                            }
                        });
                    });
                }
            },
            toolbar: {
                hoverAnimation: true, //Enable/disable small animation on mouse hover to a toolbar item.
                hoverAnimationDuration: 60, //Duration of the hover animation.
                hoverAnimationEasing: undefined, //Easing of the hover animation. Uses jQuery's default animation ('swing') if set to undefined.
                items: [
                    {
                        icon: _nameSubDomain + '/Content/images/add.png',
                        text: 'Thêm mới quận huyện',
                        click: function () {
                            _openWinDowAdQuanHuyen();
                        }
                    }
                ] //Array of your custom toolbar items.
            },
            fields: {
                MA_QUAN: {
                    key: true,
                    edit: false,
                    create: false,
                    //list:false,
                    width: '3%',
                    display: function (tbData) {
                        var $img = $('<img src="' + _nameSubDomain + '/Content/images/1356080636_cog.png" style="cursor:pointer;" title="Thông tin phường xã" />');
                        //Open child table when user clicks the image
                        $img.click(function () {
                            $('#page_quan_huyen_TableContainer').jtable('openChildTable',
                                   $img.closest('tr'), //Parent row
                                   {
                                       title: 'Phường xã của quận huyện ' + tbData.record.TEN_QUAN,
                                       toolbar: {
                                           hoverAnimation: true, //Enable/disable small animation on mouse hover to a toolbar item.
                                           hoverAnimationDuration: 60, //Duration of the hover animation.
                                           hoverAnimationEasing: undefined, //Easing of the hover animation. Uses jQuery's default animation ('swing') if set to undefined.
                                           items: [
                                               {
                                                   icon: _nameSubDomain + '/Content/images/add.png',
                                                   text: 'Thêm mới phường xã',
                                                   click: function () {
                                                       _openWinDowAdPhuongXa(tbData.record.MA_QUAN, tbData.record.TEN_QUAN);
                                                   }
                                               }
                                           ] //Array of your custom toolbar items.
                                       },
                                       actions: {
                                           listAction: _nameSubDomain + '/QuanHuyen/ListPhuongXa?qhId=' + tbData.record.MA_QUAN,
                                           //deleteAction: _nameSubDomain + '/Danhmuc/DeleteToQuanLy',
                                           deleteAction: function (postData) {
                                               console.log("deleting from custom function...");
                                               return $.Deferred(function ($dfd) {

                                                   $("#IndexPageQuanHuyenAddUp").mask("Dữ liệu đang được xóa");

                                                   $.ajax({
                                                       url: _nameSubDomain + '/QuanHuyen/DeletePhuongXa',
                                                       type: 'POST',
                                                       dataType: 'json',
                                                       data: postData,
                                                       success: function (data) {

                                                           $dfd.resolve(data);
                                                           setTimeout(function () { $("#IndexPageQuanHuyenAddUp").unmask(); }, 600);

                                                       },
                                                       error: function () {
                                                           $dfd.reject();
                                                       }
                                                   });
                                               });
                                           }

                                       },
                                       fields: {
                                           MA_PHUONG: {
                                               key: true,
                                               //create: false,
                                               //edit: false,
                                               list: true,
                                               //title: 'Mã MVT',
                                               width: '3%',
                                           },
                                           TEN_PHUONG: {
                                               title: 'Tên Phường',
                                               width: '20%'
                                           },
                                           CLAT: {
                                               title: 'Lat',
                                               edit: false,
                                               width: '10%'
                                           },
                                           CLONG: {
                                               title: 'Long',
                                               width: '10%'
                                           },
                                           GHICHU: {
                                               title: 'Ghi Chú',
                                               edit: false,
                                               width: '20%'
                                           },
                                           UPDATE: {
                                               display: function (data) {
                                                   return '<button title="Edit Record" onclick="return _UpdatePhuongXa(\'' + data.record.MA_PHUONG + '\', \'' + tbData.record.TEN_QUAN + '\')" class="jtable-command-button jtable-edit-command-button"><span></span></button>';
                                               },
                                               create: false,
                                               edit: false,
                                               width: '3%'
                                           },
                                       }
                                   }, function (data) { //opened handler
                                       data.childTable.jtable('load');
                                   });
                        });
                        //Return image to show on the person row
                        return $img;
                    }
                },
                TEN_QUAN: {
                    title: 'Tên Quận',
                    width: '20%'
                },
                CLAT: {
                    title: 'Lat',
                    width: '10%'
                },
                CLONG: {
                    title: 'Long',
                    width: '15%'
                },
                UPDATE: {
                    display: function (data) {
                        return '<button title="Edit Record" onclick="return _UpdateQuanHuyen(\'' + data.record.MA_QUAN + '\')" class="jtable-command-button jtable-edit-command-button"><span></span></button>';
                    },
                    create: false,
                    edit: false,
                    width: '3%'
                },


            },
            //Initialize validation logic when a form is created
            formCreated: function (event, data) {
                //data.form.find('input[name="TEN"]').addClass('validate[required]');
                data.form.validationEngine();
            },

        });

        $('#page_quan_huyen_TableContainer').jtable('load');

        setTimeout(function () { $("#IndexPageQuanHuyenAddUp").unmask(); }, 3000);

    });

    function _openWinDowAdQuanHuyen() {

        loadwindowOnContent(_nameSubDomain + "/QuanHuyen/AddQuanHuyen", "window_addupdate_quanhuyen_page", "Thêm thông tin quận huyện", 630, 400);

    }

    function _UpdateQuanHuyen(id) {

        loadwindowOnContent(_nameSubDomain + "/QuanHuyen/UpdateQuanHuyen?maQH=" + id, "window_addupdate_quanhuyen_page", "Cập nhật thông tin quận huyện", 630,400);

    }


    function _openWinDowAdPhuongXa(id, name) {

        loadwindowOnContent(_nameSubDomain + "/QuanHuyen/AddPhuongXa?maquan=" + id + "&namequan=" + name, "window_addupdate_phuongxa_page", "Cập nhật thông tin phường xã của quận huyện " + name, 600, 400);
         
    }

    function _UpdatePhuongXa(idPX, NameQH) {

        loadwindowOnContent(_nameSubDomain + "/QuanHuyen/UpdatPhuongXa?maPx=" + idPX + "&NameQH=" + NameQH, "window_addupdate_phuongxa_page", "Cập nhật thông tin phường xã của quận huyện " + name, 600, 400);

    }

</script>
